﻿Imports DotNetNuke.Common.Utilities.DataCache
Imports DotNetNuke.Entities.Modules

Namespace RTP.RSSFeed

    Public Class RSSSettings
#Region "Private Members"
        Private _allsettings As Hashtable
        Private _moduleID As Integer = -1

        Private _rssfeedroottitle As String = "RTP RSS Feed"
        Private _rssfeedrootdescription As String = "RSS Feed by RTP. Outputs an RSS feed based on a defined SQL Query"
        Private _rssfeedtitle As Boolean = True
        Private _rssfeeddescription As Boolean = True
        Private _rssfeedlink As Boolean = True
        Private _rssfeedguid As Boolean = False
        Private _rssfeedpubdate As Boolean = False
        Private _rssfeedcreator As Boolean = False
        Private _rssfeedcategory As Boolean = False
        Private _rssimageurl As Boolean = False
        Private _rssfeedsqlquery As String = ""
        Private _rsssecurity As Boolean = False
        Private _rssnoviewperms As String = "You do not have permissions for this RSS Feed"
        Private _rssutcconvert As Boolean = False
        Private _rssutmsource As String = ""
        Private _rssutmmedium As String = ""
#End Region

#Region " Constructors "
        Public Sub New()
        End Sub

        Public Sub New(ByVal ModuleId As Integer)
            _moduleID = ModuleId
            Dim mc As New ModuleController
            _allsettings = mc.GetModuleSettings(_moduleID)

            ReadValue(_allsettings, "rssfeedroottitle", rssfeedroottitle)
            ReadValue(_allsettings, "rssfeedrootdescription", rssfeedrootdescription)
            ReadValue(_allsettings, "rssfeedtitle", rssfeedtitle)
            ReadValue(_allsettings, "rssfeeddescription", rssfeeddescription)
            ReadValue(_allsettings, "rssfeedlink", rssfeedlink)
            ReadValue(_allsettings, "rssfeedguid", rssfeedguid)
            ReadValue(_allsettings, "rssfeedpubdate", rssfeedpubdate)
            ReadValue(_allsettings, "rssfeedcreator", rssfeedcreator)
            ReadValue(_allsettings, "rssfeedcategory", rssfeedcategory)
            ReadValue(_allsettings, "rssimageurl", rssimageurl)
            ReadValue(_allsettings, "rssfeedsqlquery", rssfeedsqlquery)
            ReadValue(_allsettings, "rssnoviewperms", rssnoviewperms)
            ReadValue(_allsettings, "rssutcconvert", rssutcconvert)
            ReadValue(_allsettings, "rssutmsource", rssutmsource)
            ReadValue(_allsettings, "rssutmmedium", rssutmmedium)

        End Sub
#End Region

#Region " Public Methods "

        Public Sub SaveSettings(ByVal ModuleId As Integer)

            Dim objModules As New ModuleController
            With objModules
                .UpdateModuleSetting(ModuleId, "rssfeedroottitle", Me.rssfeedroottitle.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedrootdescription", Me.rssfeedrootdescription.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedtitle", Me.rssfeedtitle.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeeddescription", Me.rssfeeddescription.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedlink", Me.rssfeedlink.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedguid", Me.rssfeedguid.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedpubdate", Me.rssfeedpubdate.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedcreator", Me.rssfeedcreator.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedcategory", Me.rssfeedcategory.ToString)
                .UpdateModuleSetting(ModuleId, "rssimageurl", Me.rssimageurl.ToString)
                .UpdateModuleSetting(ModuleId, "rssfeedsqlquery", Me.rssfeedsqlquery.ToString)
                .UpdateModuleSetting(ModuleId, "rssnoviewperms", Me.rssnoviewperms.ToString)
                .UpdateModuleSetting(ModuleId, "rssutcconvert", Me.rssutcconvert.ToString)
                .UpdateModuleSetting(ModuleId, "rssutmsource", Me.rssutmsource.ToString)
                .UpdateModuleSetting(ModuleId, "rssutmmedium", Me.rssutmmedium.ToString)
            End With
            Dim CacheKey As String = "RSSSettings" & ModuleId.ToString
            SetCache(CacheKey, Me)

        End Sub

        Public Function GetRSSSettings(ByVal ModuleID As Integer) As RSSSettings
            _moduleID = ModuleID
            If _moduleID > 0 Then
                Dim CacheKey As String = "RSSSettings" & ModuleID.ToString
                Dim bs As RSSSettings = Nothing
                bs = CType(GetCache(CacheKey), RSSSettings)
                If bs Is Nothing Then
                    bs = New RSSSettings(_moduleID)
                    SetCache(CacheKey, bs)
                End If
                Return bs
            End If
            Return Nothing
        End Function

#End Region

#Region "Public Properties "
        Public Property rssfeedtitle() As Boolean
            Get
                Return _rssfeedtitle
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedtitle = Value
            End Set
        End Property

        Public Property rssfeedlink() As Boolean
            Get
                Return _rssfeedlink
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedlink = Value
            End Set
        End Property

        Public Property rssfeedguid() As Boolean
            Get
                Return _rssfeedguid
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedguid = Value
            End Set
        End Property

        Public Property rssfeedpubdate() As Boolean
            Get
                Return _rssfeedpubdate
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedpubdate = Value
            End Set
        End Property

        Public Property rssfeedcreator() As Boolean
            Get
                Return _rssfeedcreator
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedcreator = Value
            End Set
        End Property

        Public Property rssfeedcategory() As Boolean
            Get
                Return _rssfeedcategory
            End Get
            Set(ByVal Value As Boolean)
                _rssfeedcategory = Value
            End Set
        End Property

        Public Property rssimageurl() As Boolean
            Get
                Return _rssimageurl
            End Get
            Set(ByVal Value As Boolean)
                _rssimageurl = Value
            End Set
        End Property

        Public Property rsssecurity() As Boolean
            Get
                Return _rsssecurity
            End Get
            Set(ByVal Value As Boolean)
                _rsssecurity = Value
            End Set
        End Property

        Public Property rssutcconvert() As Boolean
            Get
                Return _rssutcconvert
            End Get
            Set(ByVal Value As Boolean)
                _rssutcconvert = Value
            End Set
        End Property

        Public Property rssfeeddescription() As Boolean
            Get
                Return _rssfeeddescription
            End Get
            Set(ByVal Value As Boolean)
                _rssfeeddescription = Value
            End Set
        End Property

        Public Property rssfeedroottitle() As String
            Get
                Return _rssfeedroottitle
            End Get
            Set(ByVal Value As String)
                _rssfeedroottitle = Value
            End Set
        End Property

        Public Property rssfeedrootdescription() As String
            Get
                Return _rssfeedrootdescription
            End Get
            Set(ByVal Value As String)
                _rssfeedrootdescription = Value
            End Set
        End Property

        Public Property rssfeedsqlquery() As String
            Get
                Return _rssfeedsqlquery
            End Get
            Set(ByVal Value As String)
                _rssfeedsqlquery = Value
            End Set
        End Property

        Public Property rssnoviewperms() As String
            Get
                Return _rssnoviewperms
            End Get
            Set(ByVal Value As String)
                _rssnoviewperms = Value
            End Set
        End Property

        Public Property rssutmsource() As String
            Get
                Return _rssutmsource
            End Get
            Set(ByVal Value As String)
                _rssutmsource = Value
            End Set
        End Property

        Public Property rssutmmedium() As String
            Get
                Return _rssutmmedium
            End Get
            Set(ByVal Value As String)
                _rssutmmedium = Value
            End Set
        End Property
#End Region

#Region " Private Methods "

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As String)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), String)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Integer)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Integer)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Boolean)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Boolean)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As System.Web.UI.WebControls.FirstDayOfWeek)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(CInt(ValueTable.Item(ValueName)), System.Web.UI.WebControls.FirstDayOfWeek)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Double)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Double)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Private Shared Sub ReadValue(ByRef ValueTable As Hashtable, ByVal ValueName As String, ByRef Variable As Single)
            If Not ValueTable.Item(ValueName) Is Nothing Then
                Try
                    Variable = CType(ValueTable.Item(ValueName), Single)
                Catch ex As Exception
                End Try
            End If
        End Sub

#End Region
    End Class

End Namespace